/**
 * author wen
 * &copy; CUNYU GROUP
 * email wjd_13@hotmail.com
 */
package com.cunyu.action;

import com.cunyu.service.FavoriteService;
import com.cunyu.service.OrderPoolService;
import com.cunyu.service.PushService;
import com.cunyu.util.PushCheckUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * 自动推单 ，定时任务
 * @author win
 * 2019/05/21-10:44
 */
@Component
public class OrderPoolCheckTask {

    private static Logger logger = LoggerFactory.getLogger(OrderPoolCheckTask.class) ;

    @Resource
    OrderPoolService orderPoolService ;

    @Resource
    FavoriteService favoriteService ;

    @Resource
    PushService pushService ;

    @Scheduled(cron = "0 32 10 1/1 * ? ") // 间隔5秒执行
    public void pushTask() {
        String taskID = UUID.randomUUID().toString();
        logger.info("start "+taskID+" to push .");
        List<Map<String, Object>> users = favoriteService.userLike();
        List<Map<String, Object>> orders = orderPoolService.pushOrders();
        PushCheckUtil.check(users,orders,pushService);
        logger.info("user num is "+users.size() +" ,has new orders num is "+orders.size());
        logger.info("end task :"+taskID);
    }

}
